package com.net.j8583;

import com.net.j8583.field.Field;
import com.net.j8583.field.FieldComp;
import com.net.utils.Socket;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 *
 * Date: 14-1-24
 * Time: 16:08
 */
public class Protocol8583BocRefund extends Protocol8583<Map, Map> {

    public Protocol8583BocRefund(Map map, Define8583 define8583) {
        super(map, define8583);
    }

    public Map getCommunicateConfigInfo() {
        Map map = new HashMap();
        map.put(Socket.TCP_IP, "127.0.0.1");
        map.put(Socket.TCP_PORT, 8089);
        map.put(Socket.TCP_TIMEOUT_CONN, 10000);
        map.put(Socket.TCP_TIMEOUT_READ, 10000);
        return map;
    }


    @Override
    public void putRequestParam() {
        addFiled(-3, "6000350000");
        addFiled(-2, "0100");
        addFiled(-1, "0200");
        addFiled(2, (String) req.get("cardNo"));
        addFiled(3, "000000");
        addFiled(4, "1000");
        addFiled(8, "20131112.01");
        addFiled(11, "100011");
        addFiled(14, "1607");
        addFiled(22, "012");
        addFiled(24, "025");
        addFiled(25, "8");
        addFiled(32, "2102");
        addFiled(41, "31010000");
        addFiled(42, "104310153111011");
        addFiled(44, "123456789");
        addFiled(49, "156");

        addSubField(62,1,"0621");
        addSubField(62,2,"100622");
        addSubField(62,3,"20140101235959");
        addSubField(62,4,"100624");

        setNeedMac(true);
        setZmk("48864EA979EE933748864EA979EE9337");
        setZak("CAD2FA122EA0560DACA17482E13ED175");
    }

    @Override
    public Map toResult() {
        Map map = new LinkedHashMap();
        map.put("cardNo", responseData.get(2).getRespDecodeValue());
        map.put("currencyCode", responseData.get(49).getRespDecodeValue());
        FieldComp comp = (FieldComp)requestData.get(62);
        map.put("origType",comp.getSubField(1).getRespDecodeValue());
        map.put("origFlowId",comp.getSubField(2).getRespDecodeValue());
        map.put("origDate",comp.getSubField(3).getRespDecodeValue());
        map.put("origOrderId",comp.getSubField(4).getRespDecodeValue());

        return map;
    }
}
